


# Libraries
library(rio)
library(countrycode)
library(tidyverse)
library(ggpubr)
library(arsenal)
library(viridis)
library(wesanderson)

setwd("~/03_figure1")

## LOAD WDI DATA
dv_wdi <- import("WDI_2005_2020.csv") %>%
  filter(year == 2000 & iso3c!="") %>%
  filter(series == 2020.750 | series == 2005.25) %>%
  select(-year) %>%
  pivot_wider(id_cols = c(iso3c,country), names_from = "series", values_from = "gdp_growth") %>%
  rename(growth_wdi2005 = `2005.25`,
         growth_wdi2020 = `2020.75`) %>%
  select(iso3c,growth_wdi2020,growth_wdi2005) %>%
  mutate(difference = growth_wdi2005-growth_wdi2020,
         difference_cat = ifelse(difference>(-1) & difference<1, "Less than 1 pp", 
                                 ifelse(difference<(-1) & difference>(-5) | difference>1 & difference<5, "1-5 pp",
                                        "Over 5 pp"))) %>%
  mutate(difference_cat = as.factor(difference_cat),
         difference_cat = relevel(difference_cat, ref = "Less than 1 pp"),
         iso3c = as.factor(iso3c),
         increase = ifelse(difference>0, "Decrease","Increase")) %>%
  filter(!is.na(difference_cat)) %>%
  arrange(difference) %>%
  mutate(country = countrycode(iso3c, 'iso3c','country.name', warn = T))


# Estimate of GDP Growth in 2000
dv_wdi %>%
  slice_max(abs(difference), n = 20) %>%
  ggplot(aes(growth_wdi2020, reorder(country, -growth_wdi2020), color = increase)) + 
  geom_segment(aes(x = growth_wdi2005, y = reorder(country, -growth_wdi2020), xend = growth_wdi2020, yend = reorder(country, -growth_wdi2020))) +
  geom_point(size = 3) + theme_minimal() + labs(color = "Change from April 2005 to September 2020", x = "GDP Growth (%)", y = " ") +
  #scale_color_manual(values = wes_palette("Zissou1")) +
  scale_color_manual(values = c("#409cb4","#ed4406")) + 
  theme(legend.position="bottom", axis.text.y = element_text(size = 12), axis.text.x = element_text(size = 12))

#ggsave("lollipop_chart.pdf", width = 8)